#include "World.h"

void Physics::World::Create()
{
    m_Impl = Common::pyCommon.createPhysicsWorld();
    m_Impl->setEventListener(this);

}

void Physics::World::Update(const float &dt)
{
    m_Impl->update(dt);
}

void Physics::World::Destory()
{
    Common::pyCommon.destroyPhysicsWorld(m_Impl);
}

glm::vec3 Physics::World::GetGravity() const
{
    return GLM_VEC3(m_Impl->getGravity());
}

void Physics::World::SetGravity(const glm::vec3 &gravity)
{
    m_Impl->setGravity(RP_VEC3(gravity));
}

bool Physics::World::IsGravityEnabled() const
{
    return m_Impl->isGravityEnabled();
}

void Physics::World::SetIsGravityEnabled(bool isGravityEnabled)
{
    m_Impl->setIsGravityEnabled(isGravityEnabled);
}

bool Physics::World::IsSleepingEnabled() const
{
    return m_Impl->isSleepingEnabled();
}

void Physics::World::EnableSleeping(bool isSleepingEnabled)
{
    m_Impl->enableSleeping(isSleepingEnabled);
}

float Physics::World::GetSleepLinearVelocity() const
{
    return m_Impl->getSleepLinearVelocity();
}

void Physics::World::SetSleepLinearVelocity(float sleepLinearVelocity)
{
    m_Impl->setSleepLinearVelocity(sleepLinearVelocity);
}

float Physics::World::GetSleepAngularVelocity() const
{
    return m_Impl->getSleepAngularVelocity();
}

void Physics::World::SetSleepAngularVelocity(float sleepAngularVelocity)
{
    m_Impl->setSleepAngularVelocity(sleepAngularVelocity);
}

float Physics::World::GetTimeBeforeSleep() const
{
    return m_Impl->getTimeBeforeSleep();
}

void Physics::World::SetTimeBeforeSleep(float timeBeforeSleep)
{
    m_Impl->setTimeBeforeSleep(timeBeforeSleep);
}

Physics::RigidBody Physics::World::CreateRigidBody(const glm::vec3 &pos, const glm::quat &rot)
{

    rp3d::Transform transform;
    transform.setPosition(RP_VEC3(pos));
    transform.setOrientation(RP_QUAT(rot));
    return Physics::RigidBody(m_Impl->createRigidBody(transform));
}

Physics::CollisionBody Physics::World::CreateCollisionBody(const glm::vec3 &pos, const glm::quat &rot)
{
    rp3d::Transform transform;
    transform.setPosition(RP_VEC3(pos));
    transform.setOrientation(RP_QUAT(rot));
    return Physics::CollisionBody(m_Impl->createCollisionBody(transform));

}

void Physics::World::DestroyRigidBody(Physics::RigidBody &rb)
{
    this->m_Impl->destroyRigidBody(rb.m_Impl);
}

void Physics::World::DestroyCollisionBody(Physics::CollisionBody &cb)
{
    this->m_Impl->destroyCollisionBody(cb.m_Impl);
}

void Physics::World::DestroyJoint(Physics::Joint &j)
{
    this->m_Impl->destroyJoint(j.m_Impl);
}

void Physics::World::OnContact(const rp3d::CollisionCallback::CallbackData &callbackData)
{
    PY_LOGI("callback ");
}
